<?php
App::uses('AppController', 'Controller');
/**
 * Productscategories Controller
 *
 * @property Productscategory $Productscategory
 */
class ProductscategoriesController extends AppController {
/**
 * index method
 *
 * @return void
 */
       public $displayField = 'name';

	public function index() {
		$this->Productscategory->recursive = 0;
		$productscategories = $this->Productscategory->find('all', array('conditions' => array('Productscategory.archive' => '0')));
		$this->set(compact('productscategories'));
	}

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		if (!$this->Productscategory->exists($id)) {
			throw new NotFoundException(__('Invalid productscategory'));
		}
		$options = array('conditions' => array('Productscategory.' . $this->Productscategory->primaryKey => $id));
		$this->set('productscategory', $this->Productscategory->find('first', $options));
	}

/**
 * add method
 *
 * @return void
 */
	public function add() {
		if ($this->request->is('post')) {
			$this->Productscategory->create();
			if ($this->Productscategory->save($this->request->data)) {
				$this->Session->setFlash(__('The category has been saved'),'default', array('class' => 'savesuccess'));
                                $this->redirect(array('action' => 'index'));		
                                } else {
				$this->Session->setFlash(__('This category could not be saved. Please, try again.'),'default', array('class' => 'saveerror'));
			}
		}
	}

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		if (!$this->Productscategory->exists($id)) {
			throw new NotFoundException(__('Invalid productscategory'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->Productscategory->save($this->request->data)) {
				$this->Session->setFlash(__('The category has been saved'),'default', array('class' => 'savesuccess'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('This category could not be saved. Please, try again.'),'default', array('class' => 'saveerror'));
			}
		} else {
			$options = array('conditions' => array('Productscategory.' . $this->Productscategory->primaryKey => $id));
			$this->request->data = $this->Productscategory->find('first', $options);
		}
	}

/**
 * delete method
 *
 * @throws NotFoundException
 * @throws MethodNotAllowedException
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		$this->Productscategory->id = $id;
		if (!$this->Productscategory->exists()) {
			throw new NotFoundException(__('Invalid productscategory'));
		}
		$this->request->onlyAllow('post', 'delete');
		$data = array('id' => $id, 'archive' => '1');
		if ($this->Productscategory->save($data)) {
			$this->Session->setFlash(__('Productscategory deleted'),'default', array('class' => 'savesuccess'));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('Productscategory was not deleted'),'default', array('class' => 'saveerror'));
		$this->redirect(array('action' => 'index'));
	}
}
